import pandas as pd
import matplotlib.pyplot as plt


def hottopic_analysis():
    # 读取excel文件
    data = pd.read_excel('../public/data/tables/data_orin.xlsx')

    # 定义点赞数区间
    bins = [0, 10, 100, 1000, 5000, 10000, 50000, 100000, 9999999]
    labels = ['0-10', '10-100', '100-1000', '1000-5000', '5000-10000', '10000-50000', '50000-100000', '100000-9999999']

    # 将点赞数分区
    data['区间'] = pd.cut(data['like'], bins=bins, labels=labels, right=False)

    # 统计每个区间的文章数量
    count_per_bin = data['区间'].value_counts().sort_index()

    #设置颜色参数
    base_colors = ['#76c7c0', '#f4b942', '#f45b42', '#4287f4']  # 绿 黄 红 蓝
    colors = [base_colors[i % len(base_colors)] for i in range(len(count_per_bin))]

    # 创建柱状图
    plt.figure(figsize=(12, 6))
    count_per_bin.plot(kind='bar', color=colors)
    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.xlabel('点赞数区间')
    plt.ylabel('文章数量')
    plt.title('文章点赞量分析')
    plt.xticks(rotation=45)
    plt.grid(axis='y', linestyle='--', alpha=0.7)
    plt.savefig('../public/data/img/点赞量分析.png')
    # plt.show()
